<!--
    by: yuanbiao 2020年10月15日
    name: x-score-bar
    notes:
-->
<template>
  <div :class="[prefixCls,`${prefixCls}-${type}`,`${prefixCls}-${size}`]">
    <div :class="`${prefixCls}__left`">
      <slot name="icon"><i :class="icon"></i></slot>
    </div>
    <div :class="`${prefixCls}__middle`">
      <slot name="label">{{label}}</slot>
    </div>
    <div :class="`${prefixCls}__right`">
      <div :class="`${prefixCls}__right_slider`" :style="sliderStyles">
        <div :class="`${prefixCls}__right_slider_text`">
          <slot name="value">{{value}}</slot>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
const prefixCls = 'x-score-bar'
export default {
  name: 'x-score-bar',
  props: {
    type: {
      type: String,
      default: 'default' // default|primary|info|success|warning|danger|brown
    },
    size: {
      type: String,
      default: 'default' // default|large|small
    },
    icon: {
      type: String,
      default: 'xvu-iconfont xvu-data'
    },
    label: {
      type: String,
      default: '得分'
    },
    value: {
      type: Number,
      default: 0
    },
    max: {
      type: Number,
      default: 100
    }
  },
  data() {
    return {
      prefixCls: prefixCls
    }
  },
  computed: {
    sliderStyles () {
      let percent = this.value * 100 / (parseFloat(this.max) || 100) || 0
      percent = Math.max(Math.min(percent, 100), 0)
      return {
        left: `${percent}%`
      }
    }
  }
}
</script>
